package com.lefu.risk.storm.bolt;

import java.util.Map;

import org.apache.storm.task.OutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseRichBolt;
import org.apache.storm.tuple.Fields;
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;





public class WordSplitBolt extends BaseRichBolt{

	private static final long serialVersionUID = 1L;
	
	private OutputCollector _collector ;
	
	@Override
	public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
		this._collector = collector;
	}

	@Override
	public void execute(Tuple input) {
		
		String sentence = input.getString(0);
		
		for (String word:sentence.split("[><]+")) {
			System.out.println("split sentence & emit word>>>>>>>>> " + word);
			_collector.emit(new Values(word));
		}
	}

	@Override
	public void declareOutputFields(OutputFieldsDeclarer declarer) {
		Fields fields = new Fields("word");
		declarer.declare(fields);
	}

}
